package guoanmaker.personal.business.service;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import guoanmaker.personal.business.model.AccumulateDirectlyReducedCouponLogs;
import guoanmaker.personal.business.repository.AccumulateDirectlyReducedCouponLogsRepository;
import guoanmaker.personal.business.repository.PersonalUserCouponRepository;
/**
 * 
* @ClassName: AccumulateDirectlyReducedCouponLogsService 
* @Description: AccumulateDirectlyReducedCouponLogsService
* @author Yvonne_MGL
* @date 2018年3月6日 下午5:45:10 
*  
 */
@Service
public class AccumulateDirectlyReducedCouponLogsService {
	@Resource
	private AccumulateDirectlyReducedCouponLogsRepository adrclRepository;
	
	@Resource
	private PersonalUserCouponRepository personalUserCouponRepository;
	
	/**
	 * 
	* @Description: 保存累加直减优惠券的使用日志
	* @param  couponid
	* @param  increaseDecreaseType
	* @param  increaseDecreaseAmount
	* @param  laveAmount
	* @param  orderid
	* @param  orderNumber
	* @param  remark
	* @author Yvonne_MGL 
	* @date 2018年3月7日 上午9:21:42     
	* @return void    
	* @throws 
	 */
	public void saveAdrclLog(String couponid,String increaseDecreaseType,Double increaseDecreaseAmount,String orderid,String orderNumber,String remark){
		AccumulateDirectlyReducedCouponLogs log=new AccumulateDirectlyReducedCouponLogs();
		log.setCouponid(couponid);
		log.setIncreaseDecreaseType(increaseDecreaseType);
		log.setIncreaseDecreaseTime(new Date());
		log.setIncreaseDecreaseAmount(increaseDecreaseAmount);
		log.setOrderid(orderid);
		log.setOrderNumber(orderNumber);
		log.setRemark(remark);
		if(increaseDecreaseType!=null&&increaseDecreaseType.equals("2")){
			log.setLaveAmount(personalUserCouponRepository.findOne(couponid).getTotleAmount()-increaseDecreaseAmount);
		}else{
			log.setLaveAmount(personalUserCouponRepository.findOne(couponid).getTotleAmount()+increaseDecreaseAmount);
		}
		
		adrclRepository.save(log);
	}

}
